/**
 * Copyright (C) 2009 Ignasi Fosch Alonso
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * You can reach me by mail at natx@y10k.ws
 * You can reach him by paper mail at:
 * C. LLEIDA, 41-43, 3r 1a
 * El Prat de Llobregat 08820
 * Barcelona, SPAIN
 */
package ws.y10k.swt.utils;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

/**
 * @author natx
 *
 */
public final class ShellUtils {
	
	public static void setOptimalSize(Shell shl, float percent) {
		Monitor mon = shl.getMonitor();
		Rectangle rectMonitor = mon.getBounds();
		Point pt = new Point((int)(rectMonitor.width * percent / 100), (int)(rectMonitor.height * percent / 100));
		shl.setSize(pt);
	}
	
	public static void center(Shell shl) {
		Monitor mon = shl.getMonitor();
		Rectangle rectMonitor = mon.getBounds();
		Rectangle rectShl = shl.getBounds();
		Point pt = new Point((rectMonitor.x + (rectMonitor.width - rectShl.width))/2, (rectMonitor.y + (rectMonitor.height - rectShl.height))/2);
		shl.setLocation(pt);
	}
	
	public static void redraw(Shell shl) {
		shl.redraw();
	}

}
